package com.rbac.api.mybatis.sqlProvider;


import com.rbac.api.controller.request.PostRolesListRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class AdminRolesSqlProvider {


    ///获取角色列表数据条数
    public String getRolesListCountSelective(@Param("paramRequest") PostRolesListRequest rolesListRequest){
        ///基础SQL
        SQL sql = new SQL();
        sql.SELECT("count(1)");
        sql.FROM("admin_roles");

        ///
        return sql.toString()+" limit 1 ";
    }
    ///获取角色列表数据list
    public String getRolesListDataSelective(
            @Param("paramRequest") PostRolesListRequest rolesListRequest,
            @Param("StartRow") Integer StartRow,
            @Param("pageSize") Integer pageSize
    ){
        ///基础SQL
        SQL sql = new SQL();
        sql.SELECT("ar.id,ar.role_no,ar.role_diy_no,ar.role_name,ar.role_content,ar.role_status,GROUP_CONCAT(au.user_name) AS role_member ");
        sql.FROM("admin_roles AS ar ");
        sql.LEFT_OUTER_JOIN("admin_roles_users AS aru ON ar.role_no = aru.role_no ");
        sql.LEFT_OUTER_JOIN("admin_users AS au ON aur.user_no = au.user_no ");
        sql.GROUP_BY("ar.role_no ");
        ///排序
        sql.ORDER_BY("ar.role_status DESC ");


        ///
        return sql.toString() + " limit #{StartRow,jdbcType=INTEGER} , #{pageSize,jdbcType=INTEGER}";
    }









}